/*
 * @lc app=leetcode.cn id=232 lang=cpp
 *
 * [232] 用栈实现队列
 */

// @lc code=start
#include <bits/stdc++.h>
using namespace std;
class MyQueue
{
private:
    stack<int> s[2];
    const int curr = 0;

    void transfer(int from, int to)
    {
        while (!s[from].empty())
        {
            int t = s[from].top();
            s[to].push(t);
            s[from].pop();
        }
    }

public:
    MyQueue()
    {
    }

    void push(int x)
    {
        transfer(curr, 1 - curr);
        s[curr].push(x);
        transfer(1 - curr, curr);
    }

    int pop()
    {
        int t = s[curr].top();
        s[curr].pop();
        return t;
    }

    int peek()
    {
        return s[curr].top();
    }

    bool empty()
    {
        return s[curr].empty();
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */
// @lc code=end
